import dayjs from "dayjs";

export function weekDay(date, format = undefined) {
  let week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
  return week[dayjs(date, format).day()];
}

export function weekFirstDay(date, num=0, format = undefined) {
  return dayjs(date, format).add(num, 'week').startOf('week');
}

export function weekLastDay(date, num=0, format = undefined) {
  return dayjs(date, format).add(num, 'week').endOf('week');
}

export function monthFirstDay(date, num=0, format = undefined) {
  return dayjs(date, format).add(num, 'M').startOf('month');
}

export function monthLastDay(date, num=0, format = undefined) {
  return dayjs(date, format).add(num, 'M').endOf('month');
}

/**
 * 获取两个日期之间的日期数组
 * @param {*} start 开始时间
 * @param {*} end 结束时间
 * @returns 日期数组
 */
export function betweenTwoDateDetails(start, end) {
  if (!start || !end) {
    return [];
  }

  let startDate = dayjs(start);
  let endDate = dayjs(end);
  if (startDate.isAfter(endDate)) {
    return [];
  }

  let dates = [];
  while (startDate.isBefore(endDate)) {
    dates.push(startDate.format('YYYY-MM-DD'));
    startDate.add(1, 'days');
  }
  dates.push(endDate.format('YYYY-MM-DD'));
  return dates;
}